package com.yanqu.road.server.cmd.activity.stronghold.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CROSS_STRONGHOLD_WILD_DEAL_EVENT, desc = "野外据点处理事件返回")
public class CrossStrongholdWildDealEventCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        StrongholdWarProto.CrossDealStrongholdEventResp msg = StrongholdWarProto.CrossDealStrongholdEventResp.parseFrom(packet.getBytes());

        StrongholdWarProto.DealStrongholdEventResp.Builder resp = StrongholdWarProto.DealStrongholdEventResp.newBuilder();
        resp.setRet(msg.getRet());
        resp.setDeal(msg.getDeal());
        if (msg.hasEvent()) {
            resp.setEvent(msg.getEvent());
        }
        if (msg.hasResult()) {
            String reward = msg.getResult().getReward();
            player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Stronghold, eLogMoneyType.StrongholdDealEvent);
            resp.setResult(msg.getResult());
        }
        player.sendPacket(ClientProtocol.U_STRONGHOLD_WAR_DEAL_EVENT, resp);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
